package com.example.demo.controller;

import com.example.demo.entity.Suppliers;
import com.example.demo.service.SuppliersService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/suppliers")
public class SuppliersController {

    @Autowired
    private SuppliersService suppliersService;

    @GetMapping
    public List<Suppliers> getAllSuppliers() {
        return suppliersService.list();
    }

    @GetMapping("/{id}")
    public Suppliers getSupplierById(@PathVariable Integer id) {
        return suppliersService.getById(id);
    }

    @PostMapping
    public boolean createSupplier(@RequestBody Suppliers supplier) {
        return suppliersService.save(supplier);
    }

    @PutMapping("/{id}")
    public boolean updateSupplier(@PathVariable Integer id, @RequestBody Suppliers supplier) {
        supplier.setSupplierId(id); // 假设实体中有setSupplierId方法
        return suppliersService.updateById(supplier);
    }

    @DeleteMapping("/{id}")
    public boolean deleteSupplier(@PathVariable Integer id) {
        return suppliersService.removeById(id);
    }
}

